package com.qf.controller;

import com.qf.pojo.adress;
import com.qf.service.AdressService;
import com.qf.vo.Msg;
import com.sun.jndi.cosnaming.IiopUrl;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by ZhaoHuiDong on 2020/9/14.
 */
@Controller
@RequestMapping("adress")
public class AdressController {
    @Autowired(required = false)
    private AdressService adressService;

    @RequestMapping("selectall")
    @ResponseBody
    public Msg<adress> all(){
        List<adress> list = adressService.selectAll();
        Msg<adress> msg = new Msg();
        msg.setData(list);
        return msg;
    }
    @RequestMapping(value = "delete")
    @ResponseBody
    public Msg<adress> delete(int id){
        Msg<adress> msg = new Msg<>();
        int delect = adressService.delete(id);
        if(delect == 1){
            msg.setMsg("删除成功");
            return  msg;
        }
        return  null;

    }
    @RequestMapping("add")
    @ResponseBody
    public Msg<adress> add(adress adress){
        Msg<adress> msg = new Msg<>();
        int add = adressService.add(adress);
        if(add == 1){
            msg.setMsg("添加成功");
            return msg;
        }
        return  null;
    }
   @RequestMapping("update")
   @ResponseBody
    public Msg<adress> update(adress adress){
        Msg<adress> msg = new Msg<>();
       int update = adressService.update(adress);
        if(update == 1){
            msg.setMsg("修改成功");
            return msg;
        }
      return  null;
    }
    @RequestMapping("selectone")
    @ResponseBody
    public Msg<adress> selectOne(){
        Msg<adress> msg = new Msg<>();
        List<adress> list = adressService.selectOne();
        msg.setData(list);
        return  msg;
    }
}
